package graph.editor;

import java.awt.Dimension;
import java.util.*;
import javax.swing.*;

public class GraphEditor implements FramesController {

	public final static float BASIC_STROKE = 2;
	public final static String MENU_FILE = "File";
	public final static String MENU_HELP = "Help";
	public final static String MENU_ITEM_NEW = "New";
	public final static String MENU_ITEM_SAVE = "Save";
	public final static String MENU_ITEM_OPEN = "Open";
	public final static String MENU_ITEM_CLOSE = "Close";
	public final static String MENU_ITEM_ABOUT = "About";
	public final static String MENU_ITEM_QUIT = "Quit";
	public final static String MENU_ITEM_HELP = "Help Contents";

	public final static String DIALOG_QUIT_MSG = "Do you really want to quit ?";
	public final static String DIALOG_QUIT_TITLE = "Quit ?";
	public final static String DIALOG_REG_SUCCESS = "Word is recognized";
	public final static String DIALOG_REG_FAIL = "Recognition failed!";
	public static final String DIALOG_ABOUT_MSG = "<html>" + "<h1><center>POA FINAL PROJECT</center></h1>"
			+ "<h2><center>Graph Automaton</center></h2>" + "<h3>Member:</h3>" + "<ul>" + "<li>DO Huy Hung"
			+ "<li>TRAN Hoa Nguyen" + "</ul>" + "</html>";
	public static final String DIALOG_HELP_MSG = "<html>" + "<h1><center>User's manual</center></h1>"
			+ "<ul>" + "<li>'Left click' to create state" + "<li>'ALT+ click & drag' to create transition"
			+ "<li>'CTRL+left click' to set Initial state" + "<li>'SHIFT+left click' to set Final state"
			+ "<li>'Right click' to delete state & transition" + "</ul>" + "</html>";

	public final static String TOOLBAR_REG = "Recognize";

	public final static String TITLE = "Graph";

	private static final List<JFrame> frames = new ArrayList<JFrame>();
	public static final String DIALOG_WORD_NULL = "Word is empty, enter your word to regconize!";

	public void quit() {
		int answer = JOptionPane.showConfirmDialog(null, DIALOG_QUIT_MSG, DIALOG_QUIT_TITLE,
				JOptionPane.YES_NO_OPTION);
		if (answer == JOptionPane.YES_OPTION) {
			System.exit(0);
		}
	}

	public JFrame createFrame() {
		JFrame frame = new GraphFrame(this);
		frame.setTitle(TITLE);
		frame.setPreferredSize(new Dimension(900, 650));
		int pos = 30 * (frames.size() % 5);
		frame.setLocation(pos, pos);
		frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
		frames.add(frame);
		return frame;
	}

	public void deleteFrame(JFrame frame) {
		if (frames.size() > 1) {
			frames.remove(frame);
			frame.dispose();
		} else {
			quit();
		}
	}

	public static void main(String[] args) {
		javax.swing.SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				GraphFrame gf = (GraphFrame) new GraphEditor().createFrame();
				gf.setVisible(true);
			}
		});
	}
}